<div class="table-tools clearfix" id="toolbar">
    <div style="float: left" class="table-tools-btn">
        <a class="btn btn-primary" href="add"><i class="ace-icon fa fa-plus"></i>新增配套物资</a>
    </div>
</div>
<table id="list-container"></table>
<?php $this->beginBlock('js') ?>
<script type="text/javascript">
    var urls = {
        index: 'index',
        disable: 'disable',
        enable: 'enable',
        add: 'add',
        edit: 'edit',
        products: 'products',
    }
    var tableContainer = $('#list-container')
    initTable()
    function refreshTable() {
        tableContainer.bootstrapTable('refresh', {})
    }
    function initTable () {
        tableContainer.bootstrapTable('destroy');
        var columns = [
            {title: '名称', field: 'name'},
            {title: '品牌', field: 'brand'},
            {title: '规格', field: 'spec'},
            {title: '单位', field: 'unit'},
            {title: '数量', field: 'amount'},
            {title: '已发货数量', field: 'amount'},
            {title: '最后修改时间', field: 'updated_at'},
            {title: '操作', cellStyle: {
                    css: {'max-width': '240px'},
                },class: 'actions', formatter: function(value, row, index) {
                    var html = '';
                    if (row.status==1) {
                        html += '<a action="disable" url="'+urls.disable+'">发货记录</a>'
                    }
                    html += '<a class="save-item" url="'+urls.edit+'">编辑</a>';
                    html += '<a action="remove" url="'+urls.remove+'">删除</a>';
                    return html;
                }}
        ]
        tableContainer.bootstrapTable({
            url: urls.index,
            uniqueId: "id",
            striped: true,
            columns: columns,
            queryParams: function (params) {
                return params
            }
        });
    }
</script>
<?php $this->endBlock() ?>
